#include "CBase.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "SGD Wrappers/SGD_Math.h"

CBase::CBase()
{
	m_uiRefCount = 1;
	SetPosX(0);
	SetPosY(0);
	SetType(TYPE);
	SetVelX(0);
	SetVelY(0);
	SetPower(0);
	SetRange(0);
	SetMaxHP(0);
	SetCurrHP(0);
	SetCost(0);
}
CBase::~CBase()
{

}
void CBase::Init()
{

}
void CBase::Update(float fDelta)
{
	SetPosX( GetPosX() + (GetVelX() * fDelta) );
	SetPosY( GetPosY() + (GetVelY() * fDelta) );
}
void CBase::Render()
{
}
RECT CBase::GetCollisionRect()
{
	RECT temp;
	temp.top = (LONG)GetPosY();
	temp.left = (LONG)GetPosX();
	temp.right = GetWidth() + temp.left;
	temp.bottom = GetHeight() + temp.top;
	return temp;
}
bool CBase::Collision(CBase* pBase)
{
	RECT temp;
	RECT t1 = pBase->GetCollisionRect();
	RECT t2 = GetCollisionRect();

	if(IntersectRect(&temp, &t1, &t2))
		return true;
	else
		return false;
}
bool CBase::CheckDistance(CBase *pBase,float fDelta)
{
	float myX = GetPosX() + GetWidth();
	float myY = GetPosY() + GetHeight();
	float NeighborX = pBase->GetPosX() + pBase->GetWidth()/2;
	float NeighborY = pBase->GetPosY() + pBase->GetHeight()/2;

	tVector2D tempVec;
	tempVec.fX = 0;
	tempVec.fY = -1;

	tempVec.fX = NeighborX - myX;
	tempVec.fY = NeighborY - myY;

	if(abs(Vector2DLength(tempVec)) > GetWidth() || abs(Vector2DLength(tempVec)) > GetHeight())
		return false;
	else 
		return true;
}